use ClientPlatform

function NewGuid(){

        return (S4() + S4() + "-" + S4() + "-4" + S4().substr(0,3) + "-" + S4() + "-" + S4() + S4() + S4()).toLowerCase();

    };

function S4() {

        return (((1+Math.random())*0x10000)|0).toString(16).substring(1); 

    };

function guidToBinData(guid) { 
    guid = guid.replace(/[{}-]/g, "");
    var field1 = guid.substr(0, 8); 
    var field2 = guid.substr(8, 4); 
    var field3 = guid.substr(12, 4); 
    var field4 = guid.substr(16, 4); 
    var field5 = guid.substr(20, 12); 
    field1 = field1.substr(6, 2) + field1.substr(4, 2) + 
field1.substr(2, 2) + field1.substr(0, 2) 
    field2 = field2.substr(2, 2) + field2.substr(0, 2) 
    field3 = field3.substr(2, 2) + field3.substr(0, 2) 
    var hex = field1 + field2 + field3 + field4 + field5 

    // convert hex to base64 
    var base64Digits =
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    var base64 = ""; 
    var group; 
    for (var i = 0; i < 30; i += 6) { 
        group = parseInt(hex.substr(i, 6), 16); 
        base64 += base64Digits[(group >> 18) & 0x3f]; 
        base64 += base64Digits[(group >> 12) & 0x3f]; 
        base64 += base64Digits[(group >> 6) & 0x3f]; 
        base64 += base64Digits[group & 0x3f]; 
    } 
    group = parseInt(hex.substr(30, 2), 16); 
    base64 += base64Digits[(group >> 2) & 0x3f]; 
    base64 += base64Digits[(group << 4) & 0x3f]; 
    base64 += "=="; 

    return new BinData(3,base64); 
} 

var templateCriteriaList = [
    {
        _id: guidToBinData(NewGuid()),
        Name: "Resilience",
        CriteriaEntity: "EventIndicator",
        CriteriaEntityField: "BaseEventIndicatorId",
        BaseEventIndicatorId: guidToBinData("5FD5C2EF-7E68-44D1-8B18-C673312BC624"),
        Score: null,
        CriteriaLevel2Id: db.CriteriaLevel2.findOne({ Name: "ESG Events" })._id,
        CriteriaType: 2,
        FilterId: null,
        CompaniesIdsResult: null
    },
    {
        _id: guidToBinData(NewGuid()),
        Name: "Animal Welfare",
        CriteriaEntity: "EventIndicator",
        CriteriaEntityField: "BaseEventIndicatorId",
        BaseEventIndicatorId: guidToBinData("CF82F09A-1D7E-4C6B-90C4-AD617EFD4F0C"),
        Score: null,
        CriteriaLevel2Id: db.CriteriaLevel2.findOne({ Name: "ESG Events" })._id,
        CriteriaType: 2,
        FilterId: null,
        CompaniesIdsResult: null
    }
];
db.TemplateCriteria.insert(templateCriteriaList, { ordered: true });